// index.js
// 引入SDK核心类
var R_htmlToWxml = require('../../resource/js/htmlToWxml.js');//引入公共方法
var imageUtil = require('../../resource/js/images.js');
//var GPSTransformWX = require('../../resource/js/GPSTransformWX.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    images: {},
    autoplay: true,
    interval: 3000,
    duration: 1000,
    title:'',
    address:'',
    lat:0,
    lng:0,
    id: 0,
    title: ''
  }
  , imageLoad: function (e) {
    var imageSize = imageUtil.imageUtil(e)
    this.setData({
      imagewidth: imageSize.imageWidth,
      imageheight: imageSize.imageHeight
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    //console.log(GPSTransformWX.GPSTransformWX.prototype);

    wx.setNavigationBarTitle({
      title: wx.getStorageSync('companyinfo').name,
    })

    var that = this;
    if (this.data.id > 0) {
      var id = this.data.id;
    } else {
      var id = e.id;
      this.data.id = e.id;
    }
    //初始化导航数据
    app.util.request({
      'url': 'entry/wxapp/getoldhousedetail',
      data: { id: id },
      success: function (res) {
        if (!res.data.message.errno) {
          var houseDetail = R_htmlToWxml.html2json(res.data.data.list.content);
          that.data.title = res.data.data.list.title;
          that.data.address = res.data.data.list.address;
          that.data.lat = res.data.data.list.lat;
          that.data.lng = res.data.data.list.lng;
        
          wx.setNavigationBarTitle({
            title: that.data.title + '-' + wx.getStorageSync('companyinfo').name,
          })
          
          that.setData({
            data: res.data.data.list,
            piclist: res.data.data.piclist,
            housepic: res.data.data.housepic,
            houseplan: res.data.data.houseplan,
            content: houseDetail
          })
        }
      },
      complete: function () {


        wx.hideNavigationBarLoading(); //完成停止加载
        wx.stopPullDownRefresh();
      }
    });


  },
  goMap: function (e) {
    var that = this;

    console.log(that.data.lat);
    console.log(that.data.lng);
   // var lbs = GPSTransformWX.GPSTransformWX.prototype.transform(parseFloat(that.data.lat), parseFloat(that.data.lng));
   
    wx.openLocation({
   
      latitude: that.data.lat,
      longitude: that.data.lng,
      scale: 28,
      name: that.data.title ,
      address: that.data.address
    })
  },
  doCall: function (e) {
    console.log(e.currentTarget);
    var tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel, //此号码并非真实电话号码，仅用于测试
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.onLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onShareAppMessage() {
    console.log(this.data.id)
    return {
      title: this.data.title + '-' + wx.getStorageSync('companyinfo').name,
      path: '/weixinmao_house/pages/oldhousedetail/index?id=' + this.data.id
    }
  }
})